/**
* @author AlbertDarren
* @contact 2563491540@qq.com
*/
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cctype>
using namespace std;
const int N=61;
int main_1014_2()
{
    char int2day[8][4]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
    string hours="0123456789ABCDEFGHIJKLMN";
    char c1[N]={0},c2[N]={0},c3[N]={0},c4[N]={0};
    scanf("%s%s%s%s",c1,c2,c3,c4);
    int len1=min(strlen(c1),strlen(c2)),j,minute;
    int len2=min(strlen(c3),strlen(c4));
    char wh[3]={0};
    for (int i=0;i<len1 ;++i )
    {
        if ((c1[i]==c2[i])&&(c1[i]<='G'&&c1[i]>='A'))
        {
            wh[0]=c1[i];
            j=i+1;
            break;
        }
    }
    for (int i=j;i<len1 ;++i )
    {
        if ((c1[i]==c2[i])&&((c1[i]<='N'&&c1[i]>='A')||(c1[i]>='0'&&c1[i]<='9')))
        {
            wh[1]=c1[i];
            break;
        }
    }
    for (int i=0; i<len2;++i )
    {
        if ((c3[i]==c4[i])&&(isalpha(c3[i])))
        {
            minute=i;
        }
    }
    printf("%s %02d:%02d",int2day[wh[0]-'A'],hours.find(wh[1]),minute);
	return 0;
}
